// pages/mini/mine.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    //accountNumber: app.accountInfo().accountNumber,
    //accountName: app.accountInfo().accountName,
    //accountNick: app.accountInfo().accountNick,
    accountInfo: null
  },
  onLoad(options) {

  },

  onShow() {
    let that = this;
    wx.request({
        url: app.rootUrl + '/user/getAccount',
        data: {accountId: app.accountInfo().accountId},
        header: {
          'Content-Type': 'application/x-www-form-urlencoded',
        },
        method: 'POST',
        success: function (res) {
          that.setData({
              accountInfo: res.data
          });
          wx.setStorageSync('accountInfo', res.data)
        }
      })
  },
  formSubmit: function (e){
      if(!e.detail.value.accountName){
        wx.showToast({title: '请输入名称',
        icon: 'none',})
        return false
      }
      if(!e.detail.value.accountNick){
        wx.showToast({title: '请输入昵称',
        icon: 'none',})
        return false
      }
      let that = this;
      wx.request({
          url: app.rootUrl + '/user/saveInfo',
          data: {
              accountId: app.accountInfo().accountId,
              accountName: e.detail.value.accountName,
              accountNick: e.detail.value.accountNick
            },
          header: {
            'Content-Type': 'application/json',
          },
          method: 'POST',
          success: function (res) {
            wx.showToast({title: res.data.msg,
                icon: 'none',})
            that.onShow()
          }
        })
  }
})